﻿<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>

<%
    if (Request.Cookies["userID"] == null)
    {
        Response.Write("您没有登录");
        return;
    }
    else if (Request.Cookies["groupID"] == null)
    {
        Response.Write("您还没有进入到小组页面");
        return;
    }
    else
    {
        string userID = Request.Cookies["userID"].Value;
        string userName = Request.Cookies["username"].Value;
        string content = Request.Form["content"];
        
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(Server.MapPath("~/Feeds/" + Request.Cookies["groupID"].Value + "_Feeds.xml"));

        XmlNode root = xmlDocument.SelectSingleNode("Feeds");

        int count = Convert.ToInt32(root.Attributes["count"].Value);

        count++;

        root.Attributes["count"].Value = count.ToString();

        XmlElement newFeed = xmlDocument.CreateElement("Feed");
        
        XmlAttribute attribute = xmlDocument.CreateAttribute("postDateTime");
        attribute.Value = DateTime.Now.ToString();
        newFeed.Attributes.Append(attribute);

        attribute = xmlDocument.CreateAttribute("ID");
        attribute.Value = count.ToString();
        newFeed.Attributes.Append(attribute);

        attribute = xmlDocument.CreateAttribute("userName");
        attribute.Value = userName;
        newFeed.Attributes.Append(attribute);

        attribute = xmlDocument.CreateAttribute("userID");
        attribute.Value = userID;
        newFeed.Attributes.Append(attribute);

        newFeed.InnerText = content;
        
        root.AppendChild(newFeed);
        xmlDocument.Save(Server.MapPath("~/Feeds/" + Request.Cookies["groupID"].Value + "_Feeds.xml"));
        Response.Write("1");
        return;
    }
%>